﻿CREATE PROCEDURE [dbo].[ReportUtilization]
@StartDate DATETIME, @EndDate DATETIME
AS
BEGIN
	SELECT distinct 
		   u.FullName, 
		   p.Name as Project, 
		   e.EntryDate, 
		   e.Duration, 
		   u.ExpectedHours, 
		   u.IsAdministrative,
		   (SELECT TOP 1 StartDate 
		    FROM Weeks 
		    WHERE WeekNumber = dbo.GetWeekNumber(e.EntryDate) and Year = DATEPART(yy, e.EntryDate))
		    AS WeekStartDate
	
	FROM dbo.EntryLog as e inner join
		 dbo.Users as u on (e.UserID = u.UserID) inner join
		 dbo.Projects as p on (e.ProjectID = p.ProjectID) and (p.ProjectTypeID <> 3)
	WHERE (e.EntryDate >= @StartDate) AND (e.EntryDate <= @EndDate)
	ORDER BY u.FullName, p.Name, e.EntryDate
END

